package cn.com.duiba.millionaire.center.biz.dao.impl;

import cn.com.duiba.millionaire.center.biz.constants.DatabaseSchema;
import cn.com.duiba.millionaire.center.biz.dao.BaseDao;
import cn.com.duiba.millionaire.center.biz.dao.MillionaireActivityDao;
import cn.com.duiba.millionaire.center.biz.entity.MillionaireActivityEntity;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by sty on 1/18/18.
 */
@Repository
public class MillionaireActivityDaoImpl extends BaseDao implements MillionaireActivityDao {

    @Override
    protected DatabaseSchema chooseSchema() {
        return DatabaseSchema.MILLIONAIRE_CONFIG;
    }

    @Override
    public MillionaireActivityEntity insert(MillionaireActivityEntity millionaireActivityEntity) {
        insert("insert", millionaireActivityEntity);
        return millionaireActivityEntity;
    }

    @Override
    public int updateById(MillionaireActivityEntity millionaireActivityEntity) {
        return update("updateById", millionaireActivityEntity);
    }

    @Override
    public MillionaireActivityEntity findById(Long id) {
        return selectOne("selectById",id);
    }

    @Override
    public List<MillionaireActivityEntity> findByIds(List<Long> ids) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("ids", ids);
        return selectList("selectByIds",params);
    }

    @Override
    public int findByPageCount() {
        Map<String, Object> params = Maps.newHashMap();
        return selectOne("findByPageCount",params);
    }

    @Override
    public List<MillionaireActivityEntity> findByPage(Integer pageNum, Integer pageSize) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("startIndex", (pageNum - 1) * pageSize);
        params.put("pageSize", pageSize);
        return selectList("findByPage",params);
    }

    @Override
    public int updateStatusById(Long id, Integer openStatus) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("openStatus", openStatus);
        params.put("id", id);
        return update("changeStatusById", params);
    }

    @Override
    public int deleteById(Long id) {
        return update("deleteById", id);
    }

    @Override
    public int changeAlreadyUsed(Long id, Integer alreadyUsed) {
        Map<String,Object> paramMap = new HashMap<>();
        paramMap.put("id",id);
        paramMap.put("alreadyUsed",alreadyUsed);
        return update("changeAlreadyUsed",paramMap);
    }

    @Override
    public List<Long> findIdsByAlreadyUseAndInId(List<Long> ids) {
        return selectList("findIdsByAlreadyUseAndInId",ids);
    }

    @Override
    public List<Long> findIdsByActTypeAndIdIn(List<Long> ids, Integer actType) {
        Map<String,Object> paramMap = new HashMap<>();
        paramMap.put("ids",ids);
        paramMap.put("actType",actType);
        return selectList("findIdsByActTypeAndIdIn",paramMap);
    }

    @Override
    public List<Long> findActivityIdByActype(Integer actType) {
        return selectList("findActivityIdByActype",actType);
    }
}
